﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using KPIS.DBM;
using KPIS.GERP.SERVICE.Model;

namespace KPIS.GERP.SERVICE.DAL
{
    public class MessageWarning
    {
        Common common = new Common();
        DBManager dbManager = new DBManager(DataProvider.MySQL, ConfigurationSettings.AppSettings["ConnectionString"]);

        #region Select
        public List<message_warning> GetMessageWarning(string message_seq, string message_type)
        {
            DataTable dtb;
            List<message_warning> list = new List<message_warning>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(3);
                dbManager.AddParameters(0, "@delete_status", Common.DeletedStatus);
                dbManager.AddParameters(1, "@message_seq", message_seq);
                dbManager.AddParameters(2, "@message_type", message_type);

                string strSQL = "select * from message_warning where record_status <> @delete_status"
                    + (!string.IsNullOrWhiteSpace(message_seq) ? " and message_seq = @message_seq" : "")
                    + (!string.IsNullOrWhiteSpace(message_type) ? " and message_type = @message_type" : "")
                    ;

                dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
                list = (List<message_warning>)CollectionHelper.ConvertTo<message_warning>(dtb);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (dbManager.Connection != null) {  dbManager.Connection.Close(); dbManager.Dispose();  }
            }
            return list;
        }
        #endregion
    }
}
